var koa = require('koa');
var router = require("koa-router");
var bodyParser = require("koa-body-parser");
var app = koa();

// x-response-time 计算响应时间

app.use(function *(next){
  var start = new Date;
  yield next;
  var ms = new Date - start;
  this.set('X-Response-Time', ms + 'ms');
});

// logger 打印请求日志

app.use(function *(next){
  var start = new Date;
  yield next;
  var ms = new Date - start;
  console.log('%s %s - %s', this.method, this.url, ms);
});

//参数解析器

app.use(bodyParser());

// router 路由器

app.use(router(app));
require("./routerMap")(app);

app.listen(3000);